package com.cleaningcloud.cld.controller;

import com.cleaningcloud.cld.domain.CldMaterialAllocate;
import com.cleaningcloud.cld.domain.dto.CldMaterialAllocateDto;
import com.cleaningcloud.cld.domain.vo.CldMaterialAllocateVo;
import com.cleaningcloud.cld.service.ICldMaterialAllocateService;
import com.cleaningcloud.common.core.web.controller.BaseController;
import com.cleaningcloud.common.core.web.domain.AjaxResult;
import com.cleaningcloud.common.core.web.page.TableDataInfo;
import com.cleaningcloud.common.log.annotation.Log;
import com.cleaningcloud.common.log.enums.BusinessType;
import com.cleaningcloud.common.security.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 物资调拨Controller
 *
 * @author cleaningcloud
 * @date 2024-10-28
 */
@RestController
@RequestMapping("/materialAllocate")
public class CldMaterialAllocateController extends BaseController {
    @Autowired
    private ICldMaterialAllocateService cldMaterialAllocateService;

    /**
     * 查询物资调拨列表
     */
    @RequiresPermissions("cld:materialAllocate:list")
    @GetMapping("/list")
    public TableDataInfo list(CldMaterialAllocate cldMaterialAllocate) {
        startPage();
        List<CldMaterialAllocateVo> list = cldMaterialAllocateService.selectCldMaterialAllocateList(cldMaterialAllocate);
        return getDataTable(list);
    }

    /**
     * 查询领用记录列表
     */
    @RequiresPermissions("cld:materialApply:list")
    @GetMapping("/getUseList")
    public TableDataInfo getUseList(CldMaterialAllocateDto cldMaterialAllocate) {
        startPage();
        List<CldMaterialAllocateVo> list = cldMaterialAllocateService.selectCldUseList(cldMaterialAllocate);
        return getDataTable(list);
    }


    /**
     * 获取物资调拨详细信息
     */
    @RequiresPermissions("cld:materialAllocate:query")
    @GetMapping(value = "/{materialAllocateId}")
    public AjaxResult getInfo(@PathVariable("materialAllocateId") Long materialAllocateId) {
        return success(cldMaterialAllocateService.selectCldMaterialAllocateByMaterialAllocateId(materialAllocateId));
    }

    /**
     * 新增物资调拨
     */
    @RequiresPermissions("cld:materialAllocate:add")
    @Log(title = "物资调拨", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CldMaterialAllocateDto cldMaterialAllocate) {
        return toAjax(cldMaterialAllocateService.insertCldMaterialAllocate(cldMaterialAllocate));
    }

    /**
     * 修改物资调拨
     */
    @RequiresPermissions("cld:materialAllocate:edit")
    @Log(title = "物资调拨", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CldMaterialAllocateDto cldMaterialAllocate) {
        return toAjax(cldMaterialAllocateService.updateCldMaterialAllocate(cldMaterialAllocate));
    }


    /**
     * 审核调拨
     */
    @RequiresPermissions("erp:materialAllocate:audit")
    @Log(title = "审核调拨", businessType = BusinessType.UPDATE)
    @PutMapping("/audit")
    public AjaxResult audit(@RequestBody CldMaterialAllocate cldMaterialAllocate) {
        return toAjax(cldMaterialAllocateService.auditCldMaterialAllocate(cldMaterialAllocate));
    }

    /**
     * 删除物资调拨
     */
    @RequiresPermissions("cld:materialAllocate:remove")
    @Log(title = "物资调拨", businessType = BusinessType.DELETE)
    @DeleteMapping("/{materialAllocateIds}")
    public AjaxResult remove(@PathVariable Long[] materialAllocateIds) {
        return toAjax(cldMaterialAllocateService.deleteCldMaterialAllocateByMaterialAllocateIds(materialAllocateIds));
    }
}
